package server;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.tools.ant.taskdefs.Filter;

import webWof.StrippedGameDB;



public class test  extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		try {
			response.setContentType("application/x-java-serialized-object");
			InputStream in = request.getInputStream();
			ObjectInputStream inputFromApplet = new ObjectInputStream(in);
			/**java.lang.Object o =  inputFromApplet.readObject();
			PersistenceManager pm=PMF.get().getPersistenceManager();
			Query q=pm.newQuery(GameDB.class);
			//q.setOrdering(" score descending ");
			q.setFilter(" winner == '"+"tom"+"' ");
			List<GameDB> results=(List<GameDB>) q.execute();
			ArrayList<GameDB> l=new ArrayList<GameDB>(results);
			q.setFilter(" loser == '"+"tom"+"' ");
			//q.setOrdering(" score descending ");
			results= (List<GameDB>) q.execute();;
			l.addAll(results);
			ArrayList<StrippedGameDB> retval=new ArrayList<StrippedGameDB>();
			for (GameDB g:l){
				retval.add(new StrippedGameDB(g.getWinner(), g.getLoser(), g.getDate()));
			}**/
			Object retval=WebGamesManager.getInstance().clearactiveusers();
			//for (int i=0;i<results.size();i++){
			//tom.put(results.get(i).getName(), results.get(i).getScore());}
			OutputStream outstr = response.getOutputStream();
			ObjectOutputStream oos = new  ObjectOutputStream(outstr);
			oos.writeObject(retval);
			oos.flush();
			oos.close();

		} catch (Exception e) { 
			e.printStackTrace();
		}		

	}



	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}




}



